package com.cloud.bc.controller.ajax.center;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.bc.model.domain.UserInfo;
import com.cloud.bc.model.entity.BcChats;
import com.cloud.bc.model.entity.BcNotices;
import com.cloud.bc.model.request.ChatRequest;
import com.cloud.bc.model.request.LikeRequest;
import com.cloud.bc.model.response.AjaxResp;
import com.cloud.bc.model.response.RecentChatResponse;
import com.cloud.bc.service.BcChatsService;
import com.cloud.bc.service.BcNoticesService;
import com.cloud.bc.service.BcUsersService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

@AllArgsConstructor
@RestController
@RequestMapping("m/ajax/center/notice")
public class Ajax_NoticeController {

    private final BcChatsService bcChatsService;
    private final BcUsersService bcUsersService;
    private final BcNoticesService bcNoticesService;

    @PostMapping("send")
    public AjaxResp send(HttpServletRequest request, HttpServletResponse response,
                         ChatRequest req) {
        AjaxResp ajaxResp = new AjaxResp();
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcNotices bcNotices = new BcNotices();
        bcNotices.setUserId(userInfo.getId());
        bcNotices.setTargetId(req.getUserId());
        bcNotices.setType(req.getWordType());
        bcNotices.setWords(req.getWords());
        bcNotices.setWordType(req.getWordType());
        bcNoticesService.save(bcNotices);
        bcNotices.setCreateTime(new Date());
        ajaxResp.setObj(bcNotices);
        return ajaxResp;
    }

    @GetMapping("get")
    public AjaxResp get(HttpServletRequest request, HttpServletResponse response,
                        ChatRequest req) {
        AjaxResp ajaxResp = new AjaxResp();
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        return ajaxResp;
    }

    @GetMapping("getall")
    public AjaxResp getall(HttpServletRequest request, HttpServletResponse response,
                           ChatRequest req) {
        AjaxResp ajaxResp = new AjaxResp();
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        req.setUserId(userInfo.getId());
        List<BcNotices> list = bcNoticesService.selectNoticeList(req);
        ajaxResp.setList(list);
        return ajaxResp;
    }

    /**
     * 获取系统消息
     * */
    @GetMapping("getSystemNotice")
    public AjaxResp getSystemNotice(HttpServletRequest request, HttpServletResponse response) {
        AjaxResp ajaxResp = new AjaxResp();
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        return ajaxResp;
    }
}

